<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="zhangcheng">
		<title>个人定制卡领用</title>
		<script language="javascript" type="text/javascript" src="../script/print.js"></script>		
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
		var org = Common.cOrg();			//当前机构
		function load(){
			Eui.showNavigation();
			setPages(["mainview","detview"])
		}
		//查询定制卡片
		function queryCard(){
			if (!checkForm(companyform)) return;
			var uniqueId = companyform.uniqueId.value;
			var logId = companyform.logId.value;
			$("readcardbtn").disabled = true;
			$("drawcardbtn").disabled = true;
			
			DWR.call("mgntQueryService.checkDrawPersonalCard",uniqueId,logId,function(res){
				var card = res.card;
				var cardUser = res.cardUser;
				var customer = res.customer;
				var cardType = res.cardType;
				
				var data = {}
				data.uniqueId = cardUser.uniqueId;
				data.name = customer.name;
				data.idnoTypeText = Common.getText("idno_type",customer.idnoType);
				data.idno = customer.idno;
				data.subCardType = cardType.name;
				if (card){
					data.asn = card.asn;
					data.storeStatusText = Common.getText("cardstore_status",card.storeStatus);
				}
				data.locationName = res.storeLocationName;
				Common.setValues(userform,data);
				$("readcardbtn").disabled = false;
				$("querybtn").disabled = true;
			});
		}
		
		//读卡
		function readCard(){
			var asn;
			var uniqueId = userform.uniqueId.value;
			try{
				getCard();
				asn = getAsn();
				if (asn != userform.asn.value){
					showWarning("该卡片不是客户"+userform.name.value+"的卡片");
					return;
				}
				$("drawcardbtn").disabled = false;
				showInformation("验卡成功！");
			}catch(e){
				showError("验卡失败："+e.description);
				if (showQuestion("验卡失败，是否重新定制卡片？")){
					try{
						var data = DWR.syncCall("cardMgntService.recustomizeCard",uniqueId);
						showInformation("重新申请定制卡片成功，等待制卡！");
					}catch(e){
						showError("重新申请定制卡片失败："+e.description);
					}
				}
			}
		}
		
		//领用
		function drawCard(){
			var asn = userform.asn.value;
			if (!showQuestion("是否领用卡片"+asn+"？")) return;
			if (!CardMgnt.checkCardAsn(asn)) return;
			DWR.call("cardMgntService.customizeDrawPersonalCard",asn,function(res){
				showInformation("定制卡片"+asn+"领用成功");
				
				switchPage("detview");
				CardMgnt.showPrintView("detview","customize_draw_personal_bill",res.logId,"个人定制卡领用凭证");
				try{
					WebPrint.print("billview");
				}catch(e){showError("打印出错："+e.description);return;}
				
				var cardUser = res.cardUser;
				if (cardUser.usePin)
					CardMgnt.startCardPin(asn);
			},{blockScreen:true});
		}
		
		
		//返回、重置
		function onCancel(){
			switchPage("mainview");
			userform.reset();
			CardMgnt.resetForm(companyform);
			$("querybtn").disabled = false;
			$("readcardbtn").disabled = true;
			$("drawcardbtn").disabled = true;
		}
		</script>
	</head>
	<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="mainview">
		<div class="form">
			<form id="companyform" name="companyform">
				<div class="formTitle" id="findCustomerForm_title">输入客户编号和定制业务流水号</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="col2 label5">
					<tr>
						<td>
							<label>业务流水号</label> <input type="text" name="logId" maxlength="18" onblur="checkV(this,'',true)"> <span class="des">*</span>
						</td>
						<td>
							<label>客户编号</label> <input type="text" name="uniqueId" maxlength="18" onblur="checkV(this,'',true)"> <span class="des">*</span>
						</td>
					</tr>
				</table>
			</form>
			</div>
			<div class="form">
			<form id="userform" name="userform">
				<div class="formTitle" id="findCustomerForm_title">客户信息</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="col2 label5">
					<tr>
						<td>
							<label>客户编号</label> <input type="text" name="uniqueId" readonly class="readonly">
						</td>
						<td>
							<label>客户姓名</label> <input type="text" name="name" readonly class="readonly">
						</td>
					</tr>
					<tr>
						<td>
							<label>证件类型</label> <input type="text" name="idnoTypeText" readonly class="readonly">
						</td>
						<td>
							<label>证&nbsp;件&nbsp;号</label> <input type="text" name="idno" readonly class="readonly">
						</td>
					</tr>	
					<tr>
						<td>
							<label>卡&nbsp;&nbsp;&nbsp;&nbsp;号</label> <input type="text" name="asn" readonly class="readonly">
						</td>
						<td>
							<label>卡&nbsp;类&nbsp;型</label> <input type="text" name="subCardType" readonly class="readonly">
						</td>
					</tr>	
					<tr>
						<td>
							<label>库存状态</label> <input type="text" name="storeStatusText" readonly class="readonly">
						</td>
						<td>
							<label>库存地点</label> <input type="text" name="locationName" readonly class="readonly">
						</td>
					</tr>	
				</table>
			</form>
		</div>
		<p>
			<button onclick="queryCard()" id="querybtn">查 询</button>
			<button onclick="readCard()" id="readcardbtn" disabled>验 卡</button>
			<button onclick="drawCard()" id="drawcardbtn" disabled>领 卡</button>
			<button onclick="onCancel()">重 置</button>
		</p>
	</div>
	<!--凭证页面-->
	<div id="detview" style="display:none;">
	</div>
</body>
</html>